/*
 * @Author: qianmingtian
 * @Date: 2020-05-29 15:22:18
 * @LastEditors: qianmingtian
 * @LastEditTime: 2020-07-08 09:31:04
 * @FilePath: \qianmingtian.github.io\code\ali\alili.java
 */ 
package ali;

import java.util.Scanner;

public class alili {
    public static int count(int n, final int m, final int w2, final int w3) {
        int cost = 0;
        if (m < n) {
            return cost;
        } else {
            final double r2 = w2 >> 1;
            final double r3 = w3 / 3;
            final boolean flag = (r2 >= r3);
            while (n < m) {
                if ((n << 1) >= m) {
                    cost += w2;
                    return cost;
                }
                if (n * 3 >= m) {
                    cost += w3;
                    return cost;
                }
                if ((n << 2) >= m) {
                    cost += (2 * w2);
                    return cost;
                }
                if ((n * 6) >= m) {
                    cost = cost + w2 + w3;
                    return cost;
                }
                if ((n * 9) >= m) {
                    cost = cost + w3 * 2;
                    return cost;
                } else {
                    if (flag) {
                        n = n * 3;
                        cost += w3;
                        continue;
                    } else {
                        n = n * 2;
                        cost += w2;
                        continue;
                    }

                }
            }
        }

        return cost;

    }

    public static void main(final String[] args) {
        final Scanner in = new Scanner(System.in);

        final int size = in.nextInt();

        final int[] results = new int[size];

        for (int i = 0; i < size; i++) {

            final int start = in.nextInt();
            final int target = in.nextInt();
            final int cost1 = in.nextInt();
            final int cost2 = in.nextInt();
            results[i] = count(start, target, cost1, cost2);
            System.out.println(results[i]);
        }


        in.close();

    }
}
// while(in.hasNextLine()){
// System.out.println(in.nextLine().toString());
// }